package com.controller;

import com.cac409club.common.RestResult;
import com.cac409club.common.ResultCodeConstant;
import com.service.ActivityService;
import com.service.AnnouncementService;
import com.service.ApprovalProcessService;
import com.service.AwardService;
import com.service.ClubMemberService;
import com.service.CompetitionService;
import com.service.InternalMessageService;
import com.service.PostgraduateInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.Min;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 数据统计与可视化 Controller
 * </p>
 * @author 34448
 */
@Api("数据统计与可视化")
@RequestMapping("/statistics")
@RestController
public class StatisticsController {

    @Autowired
    private ClubMemberService clubMemberService;

    @Autowired
    private AwardService awardService;

    @Autowired
    private CompetitionService competitionService;

    @Autowired
    private ActivityService activityService;

    @Autowired
    private PostgraduateInfoService postgraduateInfoService;

    @Autowired
    private AnnouncementService announcementService;

    @Autowired
    private ApprovalProcessService approvalProcessService;

    @Autowired
    private InternalMessageService internalMessageService;

    /**
     * 获取社团成员数量统计
     *
     * @param year 年份（选填）
     * @return
     */
    @GetMapping("/club-members")
    @ApiOperation("获取社团成员数量统计")
    public RestResult<List<Map<String, Object>>> getClubMembersCount(@RequestParam(required = false) @Min(value = 0, message = "年份参数无效") Integer year) {
        List<Map<String, Object>> result;
        if (year != null) {
            result = clubMemberService.countClubMembersByYear(year);
        } else {
            result = clubMemberService.countClubMembersAllYears();
        }
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取奖项分布统计
     *
     * @return
     */
    @GetMapping("/awards-distribution")
    @ApiOperation("获取奖项分布统计")
    public RestResult<List<Map<String, Object>>> getAwardsDistributionCount() {
        List<Map<String, Object>> result = awardService.countAwardsDistribution();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取比赛参与情况统计
     *
     * @return
     */
    @GetMapping("/competition-participants")
    @ApiOperation("获取比赛参与情况统计")
    public RestResult<List<Map<String, Object>>> getCompetitionParticipantsCount() {
        List<Map<String, Object>> result = competitionService.countCompetitionParticipants();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取活动发布数量统计
     *
     * @return
     */
    @GetMapping("/activity-publications")
    @ApiOperation("获取活动发布数量统计")
    public RestResult<List<Map<String, Object>>> getActivityPublicationsCount() {
        List<Map<String, Object>> result = activityService.countActivityPublications();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取考研信息分享情况统计
     *
     * @return
     */
    @GetMapping("/postgraduate-info-sharing")
    @ApiOperation("获取考研信息分享情况统计")
    public RestResult<List<Map<String, Object>>> getPostgraduateInfoSharingCount() {
        List<Map<String, Object>> result = postgraduateInfoService.countPostgraduateInfoSharing();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取公告发布数量统计
     *
     * @return
     */
    @GetMapping("/announcement-publications")
    @ApiOperation("获取公告发布数量统计")
    public RestResult<Integer> getAnnouncementPublicationsCount() {
        Integer result = announcementService.countAnnouncementPublications();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取审批流程状态统计
     *
     * @return
     */
    @GetMapping("/approval-process-status")
    @ApiOperation("获取审批流程状态统计")
    public RestResult<List<Map<String, Object>>> getApprovalProcessStatusCount() {
        List<Map<String, Object>> result = approvalProcessService.countApprovalProcessStatus();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取站内信未读数量统计
     *
     * @return
     */
    @GetMapping("/unread-messages")
    @ApiOperation("获取站内信未读数量统计")
    public RestResult<Integer> getUnreadMessagesCount() {
        Integer result = internalMessageService.countUnreadInternalMessages();
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}